import React, { useState, useEffect, useContext } from "react";
import Header from "../../components/Header/Header";
import { $pre } from "../../http/http";
import { Button } from "antd-mobile";
import "./Detail.less"
import { Toast } from "antd-mobile";
import { reqgetgoodsinfo, reqcartadd } from "../../http/api";
import { MyContext } from "../../App";
const Detail = (props) => {
  const [info, setInfo] = useState({});
  const {
    state: {
      userInfo: { uid },
    },
  } = useContext(MyContext);
  const addShop = () => {
    reqcartadd({
      uid,
      goodsid: props.match.params.id,
      num: 1,
      type:1
    });
  };
  useEffect(() => {
    reqgetgoodsinfo({ id: props.match.params.id }).then((res) => {
      setInfo(res.data.list[0]);
    });
  }, []);
  return (
    <div>
      <Header title="商品详情" back></Header>
      <div className="detail-shop">
        <img src={$pre + info.img} alt="" />
        <h3>名称：{info.goodsname}</h3>
        <h3>价格：{info.price}</h3>
        <div>市场价格：{info.market_price}</div>
        <div>描述：{info.description}</div>
        <Button color="primary" onClick={() => addShop()}>
          加入购物车
        </Button>
      </div>
    </div>
  );
};
export default Detail;
